home *** CD-ROM | disk | FTP | other *** search
- /*
- Commodore 64 Emulator v0.4 Earle F. Philhower III
- Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include <AppleEvents.h>
- #include "Processor.h"
- #include "Error.h"
- #include "Resources.h"
- #include "Preferences.h"
-
- Rect dragRect;
- EventRecord event;
- Cursor commieCursor, diskCursor;
- int programMode;
- void Initialize(), CleanUpCommodore();
-
- main()
- {
- Initialize();
- ProcessorLoop();
- EventLoop();
- CleanUpCommodore();
- }
-
- void Initialize()
- {
- int err;
- DialogPtr dialog;
-
- /* Do standard Macintosh initializations */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- /* Set up the menus, drag area */
- dragRect=qd.screenBits.bounds;
- InsetRect(&dragRect, 2, 2);
-
- /* Display the splash screen, even if for just a second... */
- dialog=GetNewDialog(kSplashDialog, nil, (WindowPtr)-1L);
- ShowWindow(dialog);
- DrawDialog(dialog);
-
- /* Do emulator initializations */
- if (err=CursorInitialize()) ExitError(err);
- if (err=MemoryInitialize()) ExitError(err);
- if (err=MenuInitialize()) ExitError(err);
- if (err=VICInitialize()) ExitError(err);
- if (err=DirInitialize()) ExitError(err);
- if (err=AppleEventInitialize()) ExitError(err);
- if (err=InstructionInitialize()) ExitError(err);
- if (err=RegisterInitialize()) ExitError(err);
- if (err=TrapInitialize()) ExitError(err);
- if (err=SerialInitialize()) ExitError(err);
- if (err=PrinterInitialize()) ExitError(err);
- if (err=FloppyInitialize()) ExitError(err);
- if (err=HardInitialize()) ExitError(err);
- if (err=PrefInitialize()) ExitError(err);
-
- /* Done with splash screen, so free its memory */
- HideWindow(dialog);
- DisposDialog(dialog);
- }
-
- int CursorInitialize()
- {
- CursHandle cursorHandle;
-
- cursorHandle=GetCursor(kCommieCursor);
- if (cursorHandle==nil) return kMissingResource;
- commieCursor=**cursorHandle;
- DisposHandle((Handle)cursorHandle);
-
- cursorHandle=GetCursor(kDiskCursor);
- if (cursorHandle==nil) return kMissingResource;
- diskCursor=**cursorHandle;
- DisposHandle((Handle)cursorHandle);
-
- return kNoError;
- }
-
- EventLoop()
- {
- int done=0;
- char theChar;
- WindowPtr theWind;
-
- while (!done)
- {
- WaitNextEvent(everyEvent, &event, 60L, nil);
- switch(event.what)
- {
- case nullEvent:
- break;
-
- case mouseDown:
- /* Call our own mouseDown handler */
- HandleMouseDown();
- break;
-
- case autoKey:
- case keyDown:
- /* We're only concerned with Option-X characters */
- theChar = event.message&charCodeMask;
- if (event.modifiers&cmdKey) DoMenuChoice(MenuKey(theChar));
- break;
-
- case updateEvt:
- theWind=(WindowPtr)event.message;
- BeginUpdate(theWind);
- switch (GetWRefCon(theWind))
- {
- case kVICWindow:
- RedrawVIC();
- break;
- case kDirWindow:
- RedrawDir();
- break;
- }
- EndUpdate(theWind);
- break;
-
- case kHighLevelEvent :
- /* Apple Events have their own dispatcher in the OS */
- AEProcessAppleEvent(&event);
- break;
-
- case app4Evt:
- if (event.message&1) SetCursor(&(qd.arrow));
- break;
- }
- }
- }
-
- HandleMouseDown()
- {
- WindowPtr theWind;
- short thePart;
-
- thePart=FindWindow(event.where, &theWind);
- switch(thePart)
- {
- case inSysWindow:
- SystemClick(&event, theWind);
- break;
-
- case inDrag:
- if (GetWRefCon(theWind)==kVICWindow) DragVICWindow(&event);
- else DragWindow(theWind, event.where, &dragRect);
- break;
-
- case inGoAway:
- if (TrackGoAway(theWind, event.where)) HideWindow(theWind);
- break;
-
- case inMenuBar:
- DoMenuChoice(MenuSelect(event.where));
- break;
-
- case inContent:
- SelectWindow(theWind);
- switch (GetWRefCon(theWind))
- {
- case kVICWindow:
- ProcessorLoop();
- break;
- case kDirWindow:
- FloppyClick(event);
- break;
- }
- break;
- }
- }
-
- void CleanUpCommodore()
- {
- AttachFloppyImage(nil);
- }
-
-